unit dialer;
//6/5/01... harvey... added try except block to trap exception when modem are configured but not properly connected on system.
interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  MDCaption, StdCtrls, ExtCtrls, ComCtrls, Buttons, AdTapi, AdPort,
  AdExcept, OoMisc,Global;

type
  TfDialForm = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Image1: TImage;
    PhoneSystem: TApdTapiDevice;
    Panel1: TPanel;
    SpeedButton1: TSpeedButton;
    Label3: TLabel;
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormActivate(Sender: TObject);
    procedure PhoneSystemTapiStatus(CP: TObject; First, Last: Boolean;
      Device, Message, Param1, Param2, Param3: Cardinal);
    procedure SpeedButton1Click(Sender: TObject);
  private
    { Private declarations }
    FPhone: String;
    FDescription: String;
    FFontColor: TColor;
  public
    { Public declarations }
  published
    {*** SPECIAL PROPERTIES ***}
    property Phone: String Read FPhone Write FPhone;
    property Description: String Read FDescription Write FDescription;
  end;

var
  fDialForm: TfDialForm;
  DialCounter: Integer;
  LoadedFlag: Boolean;
  ContinueLoad: Boolean;

implementation
{$R *.DFM}

procedure TfDialForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
 If PhoneSystem.Dialing then
   Begin
     If Application.MessageBox('Call in progress. Are you sure you want to cancel?', 'Phone Dialer', MB_OKCANCEL + MB_ICONWARNING)=IDOK then
       Begin
        PhoneSystem.CancelCall;
        CanClose := True
       End
     Else CanClose := False;
   End;
end;

procedure TfDialForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfDialForm.FormActivate(Sender: TObject);
begin
  Self.Caption:=ProductBrandVars.ProductBrandName+' Dialer';
  If Not(LoadedFlag) then
    Begin
     If PhoneSystem.TapiDevices.Count>0 then
      Begin
        PhoneSystem.SelectedDevice := PhoneSystem.TapiDevices.Strings[0];
        Label1.Caption := FDescription;
        Label2.Caption := FPhone;
//        Label3.Caption := 'CALL: ' + FPhone;
        try
          PhoneSystem.Dial (FPhone);
        except
          on EPortNotAssigned do begin//6/5/01... harvey... there are modems configured but not connected or not properyly connected ..
            Application.MessageBox ('DIALUP device(s) not properly connected.', pChar(ProductBrandVars.ProductBrandName+' Dialer'), MB_OK + MB_ICONINFORMATION);
            Close;
          end;
        end;
      End
     Else
      Begin
        Application.MessageBox ('No DIALUP device(s) found in the system.', pChar(ProductBrandVars.ProductBrandName+' Dialer'), MB_OK + MB_ICONINFORMATION);
        Close;
      End;
    End;

end;

procedure TfDialForm.PhoneSystemTapiStatus(CP: TObject; First,
  Last: Boolean; Device, Message, Param1, Param2, Param3: Cardinal);
begin
   Label3.Caption := PhoneSystem.TapiStatusMsg(Message, Param2, Param2);
end;

procedure TfDialForm.SpeedButton1Click(Sender: TObject);
begin
  If PhoneSystem.Dialing then PhoneSystem.CancelCall;
  Close;
end;

end.
